package com.ty.paypal.service;

import com.paypal.core.PayPalEnvironment;
import com.paypal.core.PayPalHttpClient;

/**
* @author ty
* @createDate 创建时间：2020年2月18日 下午3:37:24
**/
public class PayPalClient {

  /**
   *Set up the PayPal Java SDK environment with PayPal access credentials.  
   *This sample uses SandboxEnvironment. In production, use LiveEnvironment.
   */
  private PayPalEnvironment environment = new PayPalEnvironment.Sandbox(
    "Ab5ejrHwwJPS63WP4DjONzX6DbqAo7hzdJHQDrdTJklzFd2M_LaxYa3SpUXADVRAowb2h8ECA2tQjCZ_",//appid
    "ECBkfPU4RlF6Ayqp1B5NaqUO0FU36qY97-6_4FXbQ8kqyGHDFMU5-5fZoGrY29b0paIUVKrT80DMIEta");//密钥

  /**
   *PayPal HTTP client instance with environment that has access
   *credentials context. Use to invoke PayPal APIs.
   */
  PayPalHttpClient client = new PayPalHttpClient(environment);

  /**保存token**/
//  AccessToken accessToken;
  
  /**
   *Method to get client object
   *
   *@return PayPalHttpClient client
   */
  public PayPalHttpClient client() {
    return this.client;
  }
  
  /**token授权信息**/
  public String authorizationString() {
	  return this.environment.authorizationString();
  }

  /**获取accessToken**/
/*  public AccessToken getToken() throws IOException {
	  if( this.accessToken==null) {
		  AccessTokenRequest accessTokenRequest = new AccessTokenRequest(getEnvironment());
		  HttpResponse<AccessToken> response = client().execute(accessTokenRequest);
		  System.out.println("AccessToken: "+response.result().accessToken());
		  System.out.println("AccessToken: "+response.result().authorizationString());
		  this.accessToken = response.result();
	  }
	 return this.accessToken;
  }
  */
 
}